﻿requirejs.config({
    baseUrl: ".",
    paths: {
    	zepto:"javascripts/zepto.min",
    	dingtalk:"javascripts/dingtalk",
        vue: "components/vue/vue.min",
        axios: "components/axios/axios.min",
        common: "resources/js/common"
    }
});

require(["zepto","dingtalk","vue", "axios", "common"], function (zepto,dingtalk,Vue, axios, common) {
    var vm = new Vue({
        el: "#view",
        data: {
            detail: {
                incident: [],
                problem: [],
                change: [],
                release: [],
                task: [],
            }
        },
        computed: {
            incidentCount: function () {
                return this.getTotal(this.detail.incident);
            },
            problemCount: function () {
                return this.getTotal(this.detail.problem);
            },
            changeCount: function () {
                return this.getTotal(this.detail.change);
            },
            releaseCount: function () {
                return this.getTotal(this.detail.release);
            },
            taskCount: function () {
                return this.getTotal(this.detail.task);
            }
        },
        mounted: function () {
            var self = this;

            axios.get("/incident/countByStatus")
                .then(function (response) {
                    self.detail.incident = response.data;
                });

            axios.get("/problem/countByStatus")
                .then(function (response) {
                    self.detail.problem = response.data;
                });

            axios.get("/change/countByStatus")
                .then(function (response) {
                    self.detail.change = response.data;
                });

            axios.get("/release/countByStatus")
                .then(function (response) {
                    self.detail.release = response.data;
                });

            axios.get("/task/countByStatus")
                .then(function (response) {
                    self.detail.task = response.data;
                });
        },
        methods: {
            gotoIncident: function (status) {
                window.location.href = "backlogListIncident.html?status=" + encodeURI(status);
            },
            gotoProblem: function (status) {
                window.location.href = "backlogListProblem.html?status=" + encodeURI(status);
            },
            gotoChange: function (status) {
                window.location.href = "backlogListChange.html?status=" + encodeURI(status);
            },
            gotoRelease: function (status) {
                window.location.href = "backlogListRelease.html?status=" + encodeURI(status);
            },
            gotoTask: function (status) {
                window.location.href = "backlogListTask.html?status=" + encodeURI(status);
            },
            getTotal: function (list) {
                var total = 0;
                for (var i = 0; i < list.length; i++) {
                    total += list[i].count;
                }
                return total;
            }
        }
    });
});